﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Portal.Logic.Creators;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Portal.Logic.Tests.Units;

namespace Portal.Logic.Creators.Tests.Units
{
	[TestClass()]
	public class UserCreatorTests
	{
		#region From
		[TestMethod()]
		public void From_LogonIsNull_ReturnsNull()
		{
			var creator = GetCreator();
			var result = creator.From(null);

			Assert.IsNull(result);
		}

		[TestMethod()]
		public void From_LogonHasNotValidDomainSchema_ReturnsUserWithoutName()
		{
			var logon = "someLogon";

			var creator = GetCreator();
			var result = creator.From(logon);

			Assert.IsNotNull(result);
			Assert.AreEqual(logon, result.Login);
		}

		[TestMethod()]
		public void From_LogonHasNotValidNameSchema_ReturnsUserWithoutName()
		{
			var logon = @"domain\username";

			var creator = GetCreator();
			var result = creator.From(logon);

			Assert.IsNotNull(result);
			Assert.AreEqual(logon, result.Login);
		}

		[TestMethod()]
		public void From_LogonHasValidSchema_ReturnsUser()
		{
			var logon = @"domain\firstName.LastName";

			var creator = GetCreator();
			var result = creator.From(logon);

			Assert.IsNotNull(result);
			Assert.AreEqual(logon, result.Login);
			Assert.AreEqual("FirstName", result.FirstName);
			Assert.AreEqual("LastName", result.LastName);

		}
		#endregion

		private UserCreator GetCreator()
		{
			return new UserCreator();
		}
	}
}
